<template>
	<view style="background-color: #FCFCFA;height: 100%;" >
		<view style="display: flex;flex-direction: column;align-items: center;padding: 30%;">
			<image style="width: 100px;height: 100px;" src="https://qiniu.gybsky.cn/qsbsimage/public/maintain/2023/05/29/ec26f57a0e934ca88b9d3dd7b2bf8a607iqdyqym6n.gif" ></image>
			<view>正在支付中</view>
		</view>
	
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				timeStamp: '',
				nonceStr: '',
				package: '',
				signType: '',
				paySign: '',
				ticket: null,
			
			}
		},
		components: {
		},
		onLoad(options) {
			console.log("options",options)
			this.timeStamp = decodeURIComponent(options.timeStamp);
			this.nonceStr = decodeURIComponent(options.nonceStr);
			this.package = decodeURIComponent(options.package);
			this.signType = decodeURIComponent(options.signType);
			this.paySign = decodeURIComponent(options.paySign);
			// this.ticket = decodeURIComponent(options.ticket)
			var that = this
			if(!this.timeStamp){
				that.$util.Tips({title: 'timeStamp不能为空'});
				setTimeout(function(){
					uni.navigateBack()
				},2000)
				return
			} else if(!this.nonceStr){
				that.$util.Tips({title: 'nonceStr不能为空'});
				setTimeout(function(){
					uni.navigateBack()
				},2000)
				return
			}else if(!this.package){
				that.$util.Tips({title: 'packages不能为空'});
				setTimeout(function(){
					uni.navigateBack()
				},2000)
				return
			}else if(!this.signType){
				that.$util.Tips({title: 'signType不能为空'});
				setTimeout(function(){
					uni.navigateBack()
				},2000)
				return
			}else if(!this.paySign){
				that.$util.Tips({title: 'paySign不能为空'});
				setTimeout(function(){
					uni.navigateBack()
				},2000)
				return
			}
			this.weixinPay()
		},
		methods: {
			weixinPay(){
				let that = this;
				uni.showLoading({
					title: '订单支付中'
				});
				uni.requestPayment({
					timeStamp: that.timeStamp,
					nonceStr: that.nonceStr,
					package: that.package,
					signType: that.signType,
					paySign: that.paySign,
					// ticket: that.ticket,
					success: function(ress) {
						uni.hideLoading();
						that.$util.Tips({title: '支付成功'});
						setTimeout(function(){
							uni.navigateBack()
						},1200)
					},
					fail: function(e) {
						uni.hideLoading();
						that.$util.Tips({title: '取消支付'});
						setTimeout(function(){
							uni.navigateBack()
						},1200)
					},
					complete: function(e) {
						uni.hideLoading();
						//关闭当前页面跳转至订单状态
						if (e.errMsg == 'requestPayment:cancel'){
							uni.hideLoading();
							that.$util.Tips({title: '取消支付'});
							setTimeout(function(){
								uni.navigateBack()
							},1200)
						}
					},
				})
			},
			
			
		// 	weixinPay(){
		// 		let that = this;
		// 		uni.showLoading({
		// 			title: '订单支付中'
		// 		});
		// 		let data = {
		// 			timestamp: that.timeStamp,
		// 			nonceStr: that.nonceStr,
		// 			package: that.packages,
		// 			signType: that.signType,
		// 			paySign: that.paySign
		// 		};
		// 		that.$wechat.pay(data).then(res => {
		// 			if (res.errMsg == 'chooseWXPay:cancel') {
		// 				uni.hideLoading();
		// 				that.$util.Tips({title: '取消支付'});
		// 				setTimeout(function(){
		// 					uni.navigateBack()
		// 				},1200)
		// 			} else {
		// 				uni.hideLoading();
		// 				that.$util.Tips({title: '支付成功'});
		// 				setTimeout(function(){
		// 					uni.navigateBack()
		// 				},1200)
		// 			}
		// 		}).cache(res => {
		// 			uni.hideLoading();
		// 			that.$util.Tips({title: '取消支付'});
		// 			setTimeout(function(){
		// 				uni.navigateBack()
		// 			},1200)
		// 		});
		
		// 	},
			
		}
		
	}
</script>

<style lang="scss">
	page {
		background: #fff;
		height: 100%;
	}
    
	.page {
		background: #fff;
		height: 100%;
	}

	.wechat_login {
		padding: 72rpx 34rpx;

		.img image {
			width: 100%;
		}

		.btn-wrapper {
			margin-top: 86rpx;
			padding: 0 66rpx;

			button {
				width: 100%;
				height: 86rpx;
				line-height: 86rpx;
				margin-bottom: 40rpx;
				border-radius: 120rpx;
				font-size: 30rpx;

				&.btn1 {
					color: #fff;
				}

				&.btn2 {
					color: #666666;
					border: 1px solid #666666;
				}
			}
		}
	}

	.title-bar {
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 36rpx;
	}

	.icon {
		position: absolute;
		left: 30rpx;
		top: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 86rpx;
		height: 86rpx;

		image {
			width: 50rpx;
			height: 50rpx;
		}
	}
</style>
